package service;

import model.User;
import model.User_Friend;
import org.junit.Test;

import java.util.List;

public class AddFriends {

//    @Test
//    public void test() {
//        User_Friend user_friend = new User_Friend(1, 3);
//        System.out.println(addFriend(user_friend));
//    }

    public int addFriend(User_Friend user_friend) {
        List<Integer> list = new SelectFriends().selectFriends(user_friend.getId());

        if (user_friend.getId().equals(user_friend.getFriendId())) {
            return 0;
        }

        for (Integer l : list) {
            if (user_friend.getFriendId().equals(l)) {
                return 2;
            }
        }
        User user = new SelectOne().select(user_friend.getFriendId());
        if (user != null) {
            new JDBCAddFriends().addFriend(user_friend);
            User_Friend user_friend1 = new User_Friend(user_friend.getFriendId(), user_friend.getId());
            new JDBCAddFriends().addFriend(user_friend1);
            return 1;
        } else {
            return 3;
        }
    }
}
